<template>
  <div id="app2">
    <el-container>
      <el-aside width="200px">
        <el-row class="tac">
          <el-col :span="12" id="left">
            <el-menu
              default-active="2"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              :default-openeds="['2']"
            >
              <el-menu-item index="3">
                <span slot="title">欢迎光临:&nbsp;{{ username }}</span>
              </el-menu-item>
              <el-menu-item index="1">
                <i class="el-icon-menu"></i>
                <span slot="title" @click="shouye">首页</span>
              </el-menu-item>

              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-document"></i>
                  <span>页面管理</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item
                    class="span"
                    index="1-4"
                    id="el"
                    @click="myshop4"
                    >食品管理</el-menu-item
                  >
                  <el-menu-item index="1-5" id="el" @click="myshop5"
                    >订单管理</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="#">食品管理</a></el-breadcrumb-item>
          <el-dropdown>
            <span class="el-dropdown-link">
              个人中心<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
             <v-nav></v-nav>
            </el-dropdown-menu>
          </el-dropdown>
        </el-breadcrumb>
        <el-row>
            <el-button type="primary" @click="add">添加食品</el-button>
        </el-row>

        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="goodsname" label="食品名称">
          </el-table-column>
          <el-table-column prop="goodsintroduction" label="食品简介">
          </el-table-column>
          <el-table-column label="食品图片">
                <template slot-scope="scope">
                    <img class="goodsimg" :src="scope.row.goodsimg" v-if="scope.row.goodsimg" alt="">
                    <p v-else>暂时没有图片</p>
                </template>
          </el-table-column>
          <el-table-column prop="goodsprice" label="食品价格"></el-table-column>
          <el-table-column label="操作">
              <template slot-scope="scope">
                  <el-button type="primary" @click="edit(scope.row._id)">修改</el-button>
                  <el-button type="danger" @click="del(scope.row._id)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>


      </el-main>
    </el-container>
  </div>
</template>

<script>
import nav from  '../../components/nav.vue'
import dsgoodsModel from "../../model/dsgoodsModel"
import * as echarts from "echarts";
export default {
  components: {
    'v-nav':nav
  },
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      input: "",
      username: "",
      tableData:[]
    };
  },
  async created() {
    let info = window.localStorage.getItem("info");
    this.username = info;

    let {data:list} = await dsgoodsModel.getAll()
    this.tableData=list.data
  },
  methods: {
    edit(id){
      this.$router.push("/ds/goods/edit/"+id)
    },
    add(){
      this.$router.push("/ds/goods/add")
    },
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          this.tableData = this.tableData.filter((item) => item._id != id);
          await dsgoodsModel.delete(id);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    myshop4() {
      this.$router.push("/ds/shops/food");
    },
    myshop5() {
      this.$router.push("/ds/shops/order");
    },
    shouye(){
        this.$router.push("/ds/shops")
    },
    tuichu(){

    },
    handleOpen() {},
    handleClose() {},
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    },
  },
};
</script>

<style>
/* #el {
  color: #fff;
} */
.el-message-box,
.el-message-box span {
  color: #000;
}
.goodsimg{
  width:200px;
  height:auto
}

.el-message-box__btns button:nth-child(2) span {
  color: #fff ;
}
.div {
  margin-bottom: 20px;
}
.el-breadcrumb {
  border-bottom: 1px solid gray;
  margin-bottom: 20px;
}
.el-main {
  padding: 0;
  margin-left: 20px;
}
.el-aside {
  overflow: hidden;
}
#chart1,
#chart2,
#chart3,
#chart4 {
  height: 350px;
  margin: 20px 0;
}
.el-row {
  margin: 0 !important;
}
.el-aside {
  position: fixed;
}
.el-main {
  padding-left: 200px;
}
</style>
